<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "task".
 *
 * @property int $id
 * @property int $user_id 发布用户id
 * @property string $name 任务名称
 * @property string $content 任务详情
 * @property string $lng 经度
 * @property string $lat 纬度
 * @property string $province 省份
 * @property string $city 城市
 * @property string $area 地区
 * @property string $address 详细地址
 * @property int $device_main_id 主设备类型id
 * @property int $device_id 设备类型id
 * @property int $is_need_bd 是否需要应急保电
 * @property string $gz_type_ids 故障类型id集合
 * @property string $imgs 故障图片
 * @property int $state 维修状态
 * @property int $status 状态
 * @property int $created_at 创建时间
 */
class Task extends Base
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'task';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['user_id', 'device_main_id', 'device_id', 'is_need_bd', 'state', 'voltage_level', 'is_notice', 'status', 'created_at'], 'integer'],
            [['content', 'imgs'], 'string'],
            [['user_name', 'user_phone', 'name', 'lng', 'lat', 'province', 'city', 'area', 'address', 'address_detail', 'gz_type_ids'], 'string', 'max' => 255],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'user_id' => 'User ID',
            'name' => 'Name',
            'content' => 'Content',
            'lng' => 'Lng',
            'lat' => 'Lat',
            'province' => 'Province',
            'city' => 'City',
            'area' => 'Area',
            'address' => 'Address',
            'device_main_id' => 'Device Main ID',
            'device_id' => 'Device ID',
            'is_need_bd' => 'Is Need Bd',
            'gz_type_ids' => 'Gz Type Ids',
            'imgs' => 'Imgs',
            'state' => 'State',
            'status' => 'Status',
            'created_at' => 'Created At',
        ];
    }

    public function getDeviceMain(){
        return $this->hasOne(Device::class, ['id' => 'device_main_id']);
    }

    public function getDevice(){
        return $this->hasOne(Device::class, ['id' => 'device_id']);
    }

    public function getUser(){
        return $this->hasOne(User::class, ['id' => 'user_id']);
    }

    public function getVoltage(){
        return $this->hasOne(FormTag::class, ['id' => 'voltage_level']);
    }
}
